Skip to content

Add destroy_dev() function as a counterpart to create_dev()#466

Open
julianuziemblo wants to merge 4 commits intomasterfrom
julianuziemblo/remove_dev
Open

Add destroy_dev() function as a counterpart to create_dev()#466
julianuziemblo wants to merge 4 commits intomasterfrom
julianuziemblo/remove_dev

Conversation

@julianuziemblo
Copy link
Contributor

@julianuziemblo julianuziemblo commented Mar 16, 2026

Description

Motivation and Context

Depends-On: phoenix-rtos-kernel:julianuziemblo/port-unregister

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: armv7m7-imxrt117x-evk

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's device and port management by introducing explicit functions for unregistering devices and ports. This new functionality improves resource cleanup and system stability, particularly in dynamic environments where devices are frequently added and removed, by providing a structured way to remove device entries.

Highlights

  • Device Removal Functionality: Introduced a new remove_dev function to allow for the unregistration of devices from the system, enhancing device management capabilities.
  • Port Unregistration: Added a portUnregister function, providing a mechanism to unregister communication ports.
  • Robust Device Unregistration: The remove_dev implementation includes logic to handle scenarios where the device filesystem (devfs) might not be immediately available, falling back to portUnregister if necessary.
Changelog
  • include/posix/utils.h
    • Declared the remove_dev function prototype.
  • include/sys/msg.h
    • Declared the portUnregister function prototype.
  • unistd/file.c
    • Implemented the remove_dev function, including logic for interacting with the device filesystem and falling back to portUnregister.
Activity
  • The author marked this as a "New feature" type of change.
  • The changes were tested by hand on armv7m7-imxrt117x-evk.
  • All new and existing linter checks and tests passed.
  • The changes generated no new compilation warnings for any targets.
  • This PR is noted to require additional PRs to work, specifically depending on phoenix-rtos-kernel:julianuziemblo/port-unregister.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new remove_dev function and declares portUnregister for device removal. The implementation of remove_dev is mostly correct, but I've found a bug in how it handles path prefixes which could lead to incorrect behavior. I've also noted an inconsistency in error handling compared to similar functions in the same file. My review includes suggestions to address these issues.

@julianuziemblo julianuziemblo changed the title Julianuziemblo/remove dev Add remove_dev() function as a counterpart to create_dev() Mar 16, 2026
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch from ad281e5 to 066b430 Compare March 16, 2026 16:51
@nalajcie
Copy link
Member

I would rather see create_dev rewritten first. IMHO this function should not try to create /dev dir, also should either accept /dev/devname or devname param, not try to handle all cases. Probably some other thing should also be straightened out here.

@github-actions
Copy link

github-actions bot commented Mar 16, 2026

Unit Test Results

9 553 tests  ±0   8 961 ✅ ±0   53m 10s ⏱️ +38s
  591 suites ±0     592 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 2b7f7e9. ± Comparison against base commit 74852cb.

♻️ This comment has been updated with latest results.

@julianuziemblo
Copy link
Contributor Author

I would rather see create_dev rewritten first. IMHO this function should not try to create /dev dir, also should either accept /dev/devname or devname param, not try to handle all cases. Probably some other thing should also be straightened out here.

I agree with your suggestions, but it seems like they should he handled in separate PR as they are big and very breaking. This PR only adds missing functionality as a basis for drivers that need it now to work without creating excessive overhead (e.g. spawning cleanup threads just to take care of deleting their own devs).

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch from 585aecd to 066b430 Compare March 17, 2026 08:15
Copy link
Member

@agkaminski agkaminski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick, otherwise LGTM

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch from 066b430 to fb718ea Compare March 17, 2026 10:54
@julianuziemblo julianuziemblo changed the title Add remove_dev() function as a counterpart to create_dev() Add destroy_dev() function as a counterpart to create_dev() Mar 17, 2026
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch from fb718ea to 417af95 Compare March 17, 2026 11:12
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch 2 times, most recently from add8987 to 94e003f Compare March 17, 2026 12:38
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch from 94e003f to a3a1cce Compare March 17, 2026 12:38
agkaminski
agkaminski previously approved these changes Mar 17, 2026
destroy_dev() is a counterpart to create_dev() that allows for device
removal without sending messages back to the calling port unlike
remove()/unlink() functions

YT: RTOS-1254
To make destroy_dev() resemble create_dev(), a fallback was added to
unregister the port in the case we don't have a filesystem.

YT: RTOS-1254
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/remove_dev branch from 56d6117 to 2b7f7e9 Compare March 20, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants